﻿using DataAccess.Services.Gateways;
using DataAccess.Services.Interfaces;
using NHibernate;

namespace DataAccess.Services
{
	public class ServiceManager : IServiceManager
	{
		private readonly ISession session;

		public ServiceManager() : this(DataControl.SessionManager.GetSession())
		{
		}

		private ServiceManager(ISession session)
		{
			this.session = session;
		}

		public IRemittanceAdviceGateway RemittanceAdvice
		{
			get { return new RemittanceAdviceGateway(session); }
		}

		public IUserGateway User
		{
			get { return new UserGateway(session); }
		}

		public ICurrencyGateway Currency
		{
			get { return new CurrencyGateway(session); }
		}

		public IAccountGateway Account
		{
			get { return new AccountGateway(session); }
		}

		public IDocumentEnvelopeGateway DocumentEnvelope
		{
			get { return new DocumentEnvelopeGateway(session); }
		}

		public ICurrencyConversionGateway CurrencyConversion
		{
			get { return new CurrencyConversionGateway(session); }
		}

		public IDocumentEnvelopeStatusGateway DocumentEnvelopeStatusStatus
		{
			get { return new DocumentEnvelopeStatusGateway(session); }
		}

		public IRolesGateway Roles
		{
			get { return new RolesGateway(session); }
		}

		public  IDocumentTypeGateway DocumentType
		{
			get { return new DocumentTypeGateway(session); }
		}

		/// <summary>
		/// FOR TESTING PURPOSES ONLY!!! CALL THIS METHOD ONLY IN UNIT-TESTS!!!
		/// </summary>
		public void TruncateDB()
		{
			new DataControl.DataControl(session).ClearBase();
		}

		public void Dispose()
		{
			DataControl.SessionManager.CloseFactory();
		}
	}
}